﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_level
	/// </summary>
	public partial class enterprise_level
	{
		public enterprise_level()
		{}
        /// <summary>
        /// 升级会员
        /// </summary>
        /// <param name="enterprise_lid"></param>
        /// <param name="checktime">更改审核通过时间</param>
        /// <param name="status">更改状态为1 通过</param>
        /// <returns></returns>
        public int UpdateLevel(int enterprise_lid,DateTime checktime,int status)
        {
            string sql = " update enterprise_level set checktime='" + checktime + "',status="+status+" where enterprise_lid= " + enterprise_lid;

            return DbHelperSQL.ExecuteSql(sql);

        }
        /// <summary>
        /// 获取单位升级信息
        /// </summary>
        /// <param name="atid"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public DataSet GetLevelInfo(int atid, int currentPageIndex, int pageSize, out int count)
        {
            SqlParameter[] para = 
            {
                new SqlParameter("@atid",SqlDbType.Int),
                new SqlParameter("@currentPageIndex",SqlDbType.Int),
                new SqlParameter("@pageSize",SqlDbType.Int),
                new SqlParameter("@count",SqlDbType.Int)
            };

            para[0].Value = atid;
            para[1].Value = currentPageIndex;
            para[2].Value = pageSize;
            para[3].Direction = ParameterDirection.Output;

            DataSet ds = DbHelperSQL.RunProcedure("P_Get_enterprise_levelInfo", para, "ds");

            count = Convert.ToInt32(para[3].Value);

            return ds;
        }
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_lid", "enterprise_level"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_lid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_lid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_lid;

			int result= DbHelperSQL.RunProcedure("enterprise_level_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.enterprise_level model)
		{
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_lid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4),
					new SqlParameter("@submittime", SqlDbType.DateTime),
					new SqlParameter("@checktime", SqlDbType.DateTime),
					new SqlParameter("@status", SqlDbType.TinyInt,1)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.enterprise_bid;
            parameters[2].Value = model.enterprise_mid;
            parameters[3].Value = model.submittime;
            parameters[4].Value = model.checktime;
            parameters[5].Value = model.status;

            DbHelperSQL.RunProcedure("P_Add_enterprise_level", parameters, out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_level model)
		{
            int rowsAffected = 0;
            SqlParameter[] parameters = {
					new SqlParameter("@enterprise_lid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_mid", SqlDbType.Int,4),
					new SqlParameter("@submittime", SqlDbType.DateTime),
					new SqlParameter("@checktime", SqlDbType.DateTime),
					new SqlParameter("@status", SqlDbType.TinyInt,1)};
            parameters[0].Value = model.enterprise_lid;
            parameters[1].Value = model.enterprise_bid;
            parameters[2].Value = model.enterprise_mid;
            parameters[3].Value = model.submittime;
            parameters[4].Value = model.checktime;
            parameters[5].Value = model.status;

            DbHelperSQL.RunProcedure("enterprise_level_Update", parameters, out rowsAffected);
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_lid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_lid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_lid;

			DbHelperSQL.RunProcedure("enterprise_level_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_lidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_level ");
			strSql.Append(" where enterprise_lid in ("+enterprise_lidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_level GetModel(int enterprise_lid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_lid", SqlDbType.Int,4)
};
			parameters[0].Value = enterprise_lid;

			lcmyjobs.Model.enterprise_level model=new lcmyjobs.Model.enterprise_level();
			DataSet ds= DbHelperSQL.RunProcedure("enterprise_level_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["enterprise_lid"]!=null && ds.Tables[0].Rows[0]["enterprise_lid"].ToString()!="")
				{
					model.enterprise_lid=int.Parse(ds.Tables[0].Rows[0]["enterprise_lid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_bid"]!=null && ds.Tables[0].Rows[0]["enterprise_bid"].ToString()!="")
				{
					model.enterprise_bid=int.Parse(ds.Tables[0].Rows[0]["enterprise_bid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_mid"]!=null && ds.Tables[0].Rows[0]["enterprise_mid"].ToString()!="")
				{
					model.enterprise_mid=int.Parse(ds.Tables[0].Rows[0]["enterprise_mid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["status"]!=null && ds.Tables[0].Rows[0]["status"].ToString()!="")
				{
					model.status=int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_lid,enterprise_bid,enterprise_mid,status ");
			strSql.Append(" FROM enterprise_level ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_lid,enterprise_bid,enterprise_mid,status ");
			strSql.Append(" FROM enterprise_level ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

        /// <summary>
        /// 获得单位升级级别，状态
        /// </summary>
        public DataSet GetLevelById(int enterprise_bid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select * from enterprise_level where enterprise_bid = " + enterprise_bid.ToString());
            return DbHelperSQL.Query(strSql.ToString());
        }

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_level";
			parameters[1].Value = "enterprise_lid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

